﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.ComponentModel;
using System.Collections.Generic;
using System.Windows.Data;
using System.IO;
using System.Linq;

using Cinch;
using MEFedMVVM.ViewModelLocator;
using MEFedMVVM.Services.Contracts;
using MEFedMVVM.Common;


namespace Anata.Client
{
    /// <summary>
    /// </summary>
    public class TransaksiAddViewModel : ViewModelBase
    {
        #region Data
        private TransaksiViewModel currentTransaksi;

        private IMessageBoxService messageBoxService;
        private IUIVisualizerService uiVisualizerService;
        #endregion

        #region Ctor
        [ImportingConstructor]
        public TransaksiAddViewModel(
            IMessageBoxService messageBoxService,
            IUIVisualizerService uiVisualizerService)
        {
            //setup services
            this.messageBoxService = messageBoxService;
            this.uiVisualizerService = uiVisualizerService;

            CurrentTransaksi = new TransaksiViewModel(
                messageBoxService,
                uiVisualizerService,
                null,null,null);
            //KonsumenFilter.LoadedKonsumenCV.MoveCurrentToPosition(-1);
            TransaksiBaruCommand = new SimpleCommand<Object, Object>(ExecuteTransaksiBaruCommand);
            //this.viewAwareStatusService.ViewLoaded += ViewAwareStatusService_ViewLoaded;
            //commands, SimpleCommand<T1,T2> T1 is CanExecute parameter type, and T2 is Execute type
            //KonsumenSelectCommand = new SimpleCommand<Object, Object>(ExecuteKonsumenSelectCommand);
        }
        #endregion

        #region Public Properties
        // Commands
        public SimpleCommand<Object, Object> TransaksiBaruCommand { get; private set; }

        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs currentTransaksiChangeArgs =
            ObservableHelper.CreateArgs<TransaksiAddViewModel>(x => x.CurrentTransaksi);

        public TransaksiViewModel CurrentTransaksi
        {
            get { return currentTransaksi; }
            set
            {
                currentTransaksi = value;
                NotifyPropertyChanged(currentTransaksiChangeArgs);
            }
        }
        #endregion

        #region Command Handlers
        /// <summary>
        /// tpp style
        /// </summary>
        private void ExecuteTransaksiBaruCommand(Object args)
        {
            if (currentTransaksi.IsValid)
            {
                CloseActivePopUpCommand.Execute(true);
            }
        }

        #endregion

        #region IViewStatusAwareInjectionAware Members

        //public void InitialiseViewAwareService(IViewAwareStatus viewAwareStatusService)
        //{
        //    this.ViewAwareStatusService = viewAwareStatusService;
        //    //this.ViewAwareStatusService.ViewLoaded += ViewAwareStatusService_ViewLoaded;
        //}
        #endregion
        
        #region Private Methods
        //private void ViewAwareStatusService_ViewLoaded()
        //{
        //    LoadedKonsumenFilterViewModel = new KonsumenFilterViewModel(
        //        uiVisualizerService,
        //        ViewAwareStatusService);
        //}

        #endregion
    }

}
